<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>

    <title>登录</title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <!-- jquery -->
    <script th:src="@{/js/jquery.min.js}" type="text/javascript"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}" type="text/css"/>
    <script th:src="@{/bootstrap/js/bootstrap.min.js}" type="text/javascript"></script>
    <!-- jquery-validator -->
    <script th:src="@{/jquery-validation/jquery.validate.min.js}" type="text/javascript"></script>
    <script th:src="@{/jquery-validation/localization/messages_zh.min.js}" type="text/javascript"></script>
    <!-- layer -->
    <script th:src="@{/layer/layer.js}" type="text/javascript"></script>
    <!-- md5.js -->
    <script th:src="@{/js/md5.min.js}" type="text/javascript"></script>
    <!-- common.js -->
    <script th:src="@{/js/common.js}" type="text/javascript"></script>

</head>
<body>
<form id="loginForm" method="post" name="loginForm" style="width:30%; margin:0 auto;">

    <h2 style="text-align:center; margin-bottom: 20px">用户登录</h2>

    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入手机号码</label>
            <div class="col-md-8">
                <input class="form-control" id="mobile" maxlength="11" minlength="11" name="mobile" placeholder="手机号码"
                       required="true" type="text"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>

    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入密码</label>
            <div class="col-md-8">
                <input class="form-control" id="password" maxlength="16" minlength="6" name="password"
                       placeholder="密码" required="true" type="password"/>
            </div>
        </div>
    </div>

    <div class="row" style="margin-top:40px;">
        <div class="col-md-6">
            <button class="btn btn-primary btn-block" onclick="reset()" type="reset">重置</button>
        </div>
        <div class="col-md-6">
            <button class="btn btn-primary btn-block" onclick="login()" type="submit">登录</button>
        </div>
    </div>

</form>
</body>
<script>
    function login() {
        $("#loginForm").validate({
            submitHandler: function (form) {
                doLogin();
            }
        });
    }

    function doLogin() {
        g_showLoading();
        var mobile = $("#mobile").val();
        var pass = $("#password").val();
        var salt = g_passsword_salt;
        var str = "" + salt.charAt(0) + salt.charAt(2) + pass + salt.charAt(5) + salt.charAt(4);
        var passWord = md5(str);
        $.ajax({
            url: "/seckill/do_login",
            type: "POST",
            data: {
                mobile: mobile,
                passWord: passWord
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 0) {
                    layer.msg("登陆成功");
                    window.location.href = "/goods/to_list";
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.closeAll();

            }
        })
    }
</script>
</html>